home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
PASCAL
/
0920.ZIP
/
RFORM.ARC
/
_RFORM.IMP
< prev
next >
Wrap
Text File
|
1988-01-06
|
3KB
|
102 lines
function Form(Picture : string;
R : real) : string;
const NumFieldSet : set of char = ['$','#','@','*','-','+',',','.'];
var FieldStr,
TS : string;
Position,
I,K,DP : word;
begin
Position:=1; {Ignore stand alone '.' and ','}
while ((not (Picture[Position] in NumFieldSet)) and (Position <= length(Picture)))
or ((Picture[Position] in ['.',',']) and (not (Picture[Position+1] in NumFieldSet))) do
inc(Position);
if (Position > length(Picture)) then
begin
Position:=0;
FieldStr:='';
end
else
begin
I:=Position;
while (Picture[I] in NumFieldset)
and (I <= length(Picture)) do
inc(I);
FieldStr:= copy(Picture,Position,I-Position);
end;
TS:=FieldStr;
for I:=length(TS) downto 1 do
if (TS[I] in [',','+','-']) then
delete(TS,I,1);
I:=pos('.',TS);
if (I<>0) then {Calculate decimal places}
DP:=length(TS)-I
else
DP:=0;
str(R:0:DP,TS);
for I := length(TS) downto 1 do
if (TS[I] in ['+','-','.']) then {remove sign from string}
delete(TS,I,1);
I:=length(TS);
for K:=length(FieldStr) downto 1 do
begin
if (I<>0) then
if (FieldStr[K] in [',','+','-','.']) then
insert('!',TS,I+1)
else
dec(I);
end;
if (pos('@',FieldStr)<>0) then
begin
while (length(TS) < length(FieldStr)-1) do
TS:='0'+TS;
if (R<0) then
TS:='-'+TS
else
if (length(TS) < length(FieldStr)) then
TS:='0'+TS;
end
else
begin
if (pos('$',FieldStr)<>0) then
TS := '$'+TS;
if (Pos('-',FieldStr)=0)
and (Pos('+',FieldStr)=0)
and (R<0) then
TS := '-'+TS;
if (pos('*',FieldStr)<>0) then
while (length(TS) < length(FieldStr)) do
TS:='*'+TS
else
while (length(TS) < length(FieldStr)) do
TS:=' '+TS;
end;
for K:=1 to length(FieldStr) do
case FieldStr[K] of
'+' : if (R<0) then
TS[K]:='-'
else
TS[K]:='+';
'-' : if (R<0) then
TS[K]:='-'
else
TS[K]:=' ';
',' : if (TS[K] = '!') then
TS[K]:=',';
'.' : if (TS[K] = '!') and (K=length(TS)) then
TS[K]:=' '
else
TS[K]:='.';
end;
if length(TS) > length(FieldStr) then
begin
fillchar(TS,sizeof(TS),'*');
TS[0]:=FieldStr[0];
end;
for I:=1 to length(TS) do
Picture[Position+I-1]:=TS[I];
Form:=Picture;
end;